package com.learn.english.controller;

import com.learn.english.domain.R;
import com.learn.english.enums.ResultCode;
import com.learn.english.exception.BusinessException;
import com.learn.english.model.dto.RegisterDto;
import com.learn.english.service.IRegisterService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author TISNIW
 * @version 1.0
 * @date 2024/6/25 22:47
 * @desc 用户注册控制器
 */
@RestController
@RequestMapping("/register")
public class RegisterController {
    @Autowired
    private IRegisterService registerService;
    @PostMapping("/")
    public R<String> register(@RequestBody RegisterDto registerDto) {
        try {
            return R.ok(registerService.register(registerDto));
        } catch (IllegalArgumentException e) {
            throw new BusinessException(ResultCode.FAIL);
        }
    }
}
